package cn.big.bigd.biocode.dao;

import cn.big.bigd.biocode.model.Credit;
import cn.big.bigd.biocode.model.Organization;
import cn.big.bigd.biocode.model.Tool;
import cn.big.bigd.biocode.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *@Author wangfan
 *@Date 2017/12/4 12:59
 */


@Repository
public interface CreditDAO extends JpaRepository<Credit, Integer> {

   @Query(value = "select * from credits WHERE  id  in (SELECT MAX(id) FROM credits WHERE user_id=?1 GROUP BY  tool_id)" ,nativeQuery = true)
   List<Credit> findDistinctToolByUser(Long id);


   Credit findByUserAndToolAndOrganization(User u, Tool t , Organization o);



}
